package com.hustzp.com.xichuangzhu.fragment;

import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;

import com.hustzp.com.xichuangzhu.R;
import com.hustzp.com.xichuangzhu.XichuangzhuApplication;
import com.hustzp.com.xichuangzhu.adapter.CollectionKindsAdapter;
import com.hustzp.com.xichuangzhu.dao.CollectionKindsDao;
import com.hustzp.com.xichuangzhu.model.CollectionKinds;
import com.hustzp.com.xichuangzhu.model.Collections;

import java.util.HashMap;
import java.util.List;
import java.util.Locale;

/**
 * Copyright (C) 2015 The huimai mobile client Project
 * All right reserved.
 *
 * @author: wuzhimin@huimai365.com
 * @date: 2016/5/25 18:38
 * @Description:
 */
public class CategoryFragment extends Fragment {
    private ListView eLvKinds;
    private RelativeLayout rlytHeadCollectionBg;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        if("1".equals(XichuangzhuApplication.getInstance().getFanjian())){

            Configuration config = getResources().getConfiguration();
            DisplayMetrics dm = getResources() .getDisplayMetrics();
            config.locale = Locale.SIMPLIFIED_CHINESE;
            getResources().updateConfiguration(config, dm); //强制设置语言类

        }else {

            Configuration config = getResources().getConfiguration();
            DisplayMetrics dm = getResources() .getDisplayMetrics();
            config.locale = Locale.TAIWAN;
            //强制设置语言类
            getResources().updateConfiguration(config, dm);

        }
        View view = inflater.inflate(R.layout.fragment_category, container, false);
        eLvKinds = (ListView) view.findViewById(R.id.eLvKinds);

        loadData();
        return view;
    }

    private void loadData() {
        CollectionKindsDao dao = new CollectionKindsDao(getActivity());
        List<CollectionKinds> collectionKindses = dao.getCollectioinKinds();
        HashMap<String, List<Collections>> collections = new HashMap<String, List<Collections>>();
        for (CollectionKinds kind :
                collectionKindses) {
            collections.put(kind.getId(), dao.getCollectioins(kind));
        }

        BaseAdapter adapter = new CollectionKindsAdapter(getActivity(), collectionKindses, collections);
        eLvKinds.setAdapter(adapter);
    }

}
